//
// Created by tao on 2023/3/28.
//

#ifndef STL_STUDY
#define STL_STUDY


#include <vector>
#include <map>
#include <queue>
#include <array>
#include <iterator>
#include <algorithm>

#include <thread>

#include "jni.h"
#include "thread_pool_test.h"
#include "thread_pool.h"

using namespace std;

namespace my_stl {

    int main() {
        vector<int> v1 = {1, 2, 3, 4, 5, 6}, v2 = {7, 8, 9}, v_intersection;
        sort(v1.begin(), v1.end());

        // set_union()并集,set_difference()差集,set_symmetric_difference()
        set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(v_intersection));

        return 0;
    }

    void threadFunction() {
        JNIEnv *env;
        JavaVM *jvm;
        jint result = jvm->AttachCurrentThread(&env, NULL);
        if (result != JNI_OK) {

        }

        jvm->DetachCurrentThread();
    }


    void jniEnvThread() {
        auto lambdaFunction = []() {

        };
        thread myThread1(lambdaFunction);


        thread myThread(threadFunction);
        myThread.detach(); //切换到后台执行线程

        myThread.join();//



    }

    static jclass stringClass = NULL;

    // 声明全局变量
    jstring myNewString(JNIEnv *env, jchar *chars, jint len) {
        if (stringClass == NULL) {
            jclass localRefCls = env->FindClass("java/lang/String");
            if (localRefCls == NULL) {
                return NULL;
            }
            stringClass = static_cast<jclass>(env->NewGlobalRef(localRefCls));
            env->DeleteLocalRef(localRefCls);
        }
    }

    void delectGLobalRef(JNIEnv *env) {
        if (stringClass != NULL) {
            env->DeleteGlobalRef(stringClass);
        }
    }


}
#endif